package com.reggie.handler;

import com.reggie.exception.BaseException;
import com.reggie.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public R exptionHandler(BaseException ex){
        log.info(ex.getMessage());
        if (ex.getMessage().equals("Duplicate entry")){
            String name = ex.getMessage().split(" ")[2];
            return R.error(name+"已存在");
        }
        return R.error(ex.getMessage());
    }


}
